package ar.com.angrymachine.hunter.locations;

import ar.com.angrymachine.hunter.Activity;
import ar.com.angrymachine.hunter.ActivitySet;
import ar.com.angrymachine.hunter.GameSettings;
import ar.com.angrymachine.hunter.Locale;
import ar.com.angrymachine.hunter.HunterResourceManager;
import ar.com.angrymachine.hunter.gameplay.Monster;
import ar.com.angrymachine.hunter.gameplay.Spell;

public class ColossusActivitySet extends ActivitySet
{
	private static final int STATE_LEG = 0;
	private static final int STATE_WAIST = 1;
	private static final int STATE_BACK = 2;
	private static final int STATE_NECK = 3;
	
	private int state = STATE_LEG;
	
	public boolean shaking = false;
	
	private ColossusHeadActivity head = new ColossusHeadActivity(this);
	private ColossusClimbableLimbActivity leg = new ColossusClimbableLimbActivity(this, GameSettings.COLOSSUS_LEG_CLIMB_TIME, Locale.COLOSSUS_LEG);
	private ColossusClimbableLimbActivity waist = new ColossusClimbableLimbActivity(this, GameSettings.COLOSSUS_WAIST_CLIMB_TIME, Locale.COLOSSUS_WAIST);
	private ColossusClimbableLimbActivity back = new ColossusClimbableLimbActivity(this, GameSettings.COLOSSUS_BACK_CLIMB_TIME, Locale.COLOSSUS_BACK);
	private ColossusClimbableLimbActivity neck = new ColossusClimbableLimbActivity(this, GameSettings.COLOSSUS_NECK_CLIMB_TIME, Locale.COLOSSUS_NECK);
	private ColossusSoftSpotActivity softSpot = new ColossusSoftSpotActivity(this);
	
	private ColossusHandActivity leftHand = new ColossusHandActivity(this, Locale.COLOSSUS_LEFT_HAND, new HandMonster());
	private ColossusHandActivity rightHand = new ColossusHandActivity(this,Locale.COLOSSUS_RIGHT_HAND, new HandMonster());
	public boolean irritated = false;
	
	private class HandMonster extends Monster
	{
		public HandMonster()
		{
			super(Locale.COLOSSUS_HAND, HunterResourceManager.getImage("attack.png"), 8000, 100, GameSettings.COLOSSUS_HAND_ATTACK_TIME, 100);
		}
		
		protected void damageHealth(double damage)
		{
			// invulnerable
		}
		
		public void receiveAttack(double damage)
		{
			// invulnerable
		}
		
		public void receiveSpell(Spell spell)
		{
			// magic immune
		}
		
	}

	public ColossusActivitySet()
	{
		super(Locale.DEFEAT_THE_COLOSSUS);
		addActivityInTail(head);
		addActivityInTail(leftHand);
		addActivityInTail(rightHand);
		setState(STATE_LEG);
	}
	
	public void update(int delta, Activity runningActivity)
	{
		super.update(delta, runningActivity);
	}

	private void setState(int newState)
	{
		state = newState;
		// reset the activities
		switch(state)
		{
			case STATE_LEG:
				addActivityInTail(leg);
				removeActivity(waist);
				removeActivity(back);
				removeActivity(neck);
				removeActivity(softSpot);
				break;
			case STATE_WAIST:
				removeActivity(leg);
				addActivityInTail(waist);
				removeActivity(back);
				removeActivity(neck);
				removeActivity(softSpot);
				break;
			case STATE_BACK:
				removeActivity(leg);
				removeActivity(waist);
				addActivityInTail(back);
				removeActivity(neck);
				addActivityInTail(softSpot);
				break;
			case STATE_NECK:
				removeActivity(leg);
				removeActivity(waist);
				removeActivity(back);
				addActivityInTail(neck);
				break;
		}
	}

	public void onGraspLost()
	{
		setState(STATE_LEG);
	}

	public void onLimbClimbedComplete(ColossusClimbableLimbActivity limb)
	{
		if(limb == leg)
		{
			setState(STATE_WAIST);
		}
		else
		if(limb == waist)
		{
			setState(STATE_BACK);
		}
		else
		if(limb == back)
		{
			setState(STATE_NECK);
		}
	}
}
